package com.mimosa.common.message;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.mimosa.common.dao.HibernateDao;

@Repository
public class TSiteMessageDao extends HibernateDao<TSiteMessage, String> {

	/**
	 * 分页查找
	 * 
	 * @param hql
	 * @param pageSize
	 * @param pageNo
	 * @return
	 */
	/*
	 * public List<TSiteMessage> page(String hql,int pageSize, int pageNo){
	 * Session s = getSession(); Query query=s.createQuery(hql);
	 * query.setFirstResult(pageNo); query.setMaxResults(pageSize); return
	 * query.list(); }
	 */

	public int getCount(String status, String userId, Integer messageType) {
		Session s = this.getSession();
		Query query = s.createQuery(
				"select count(*) from TMessageReceiver m ,TSiteMessage s where m.siteMessage.id = s.id and receiverUserId=? and  readStatus=? and s.messageFlag=?");
		query.setString(0, userId);
		query.setString(1, status);
		query.setInteger(2, messageType);
		return ((Long) query.uniqueResult()).intValue();
	}
}